<!--
 * @Description:
 * @Version: 1.0
 * @Author: liguansheng
 * @Date: 2022-08-24 14:14:29
 * @LastEditors: liguansheng
 * @LastEditTime: 2022-08-29 09:16:14
-->
<template>
  <el-form
    :model="form"
    :rules="rules"
    label-width="120px"
    label-position="top"
  >
    <el-form-item
      label="Access Token生命周期"
      prop="accessTokenLifetime"
    >
      <el-input-number
        v-model="form.accessTokenLifeTime"
      />
    </el-form-item>
    <el-form-item
      label="Access Token类型"
      prop="accessTokenType"
    >
      <el-input-number
        v-model="form.accessTokenType"
      />
    </el-form-item>
    <el-form-item
      label="许可生命周期"
      prop="consentLifetime"
    >
      <el-input-number
        v-model="form.consentLifetime"
      />
    </el-form-item>
    <el-form-item
      label="成对主题盐"
      prop="pairWiseSubjectSalt"
    >
      <el-input
        v-model="form.pairWiseSubjectSalt"
      />
    </el-form-item>
    <el-form-item
      label=""
      prop="includeJwtId"
    >
      <el-checkbox
        v-model="form.includeJwtId"
        label="包含Jwt Id"
      />
    </el-form-item>
    <el-form-item
      label="User Sso Lifetime"
      prop="userSsoLifetime"
    >
      <el-input-number
        v-model="form.userSsoLifetime"
      />
    </el-form-item>
    <el-form-item
      label="User Code Type"
      prop="userCodeType"
    >
      <el-input
        v-model="form.userCodeType"
      />
    </el-form-item>
    <el-form-item
      label="Device Code Type"
      prop="deviceCodeLifetime"
    >
      <el-input-number
        v-model="form.deviceCodeLifetime"
      />
    </el-form-item>
    <el-form-item
      label=""
      prop="requirePkce"
    >
      <el-checkbox
        v-model="form.requirePkce"
        label="要求pkce"
      />
    </el-form-item>
    <el-form-item
      label=""
      prop="requireClientSecret"
    >
      <el-checkbox
        v-model="form.requireClientSecret"
        label="要求客户机密"
      />
    </el-form-item>
    <el-form-item
      label=""
      prop="allowAccessTokensViaBrowser"
    >
      <el-checkbox
        v-model="form.allowAccessTokensViaBrowser"
        label="允许通过浏览器访问令牌"
      />
    </el-form-item>
  </el-form>
</template>

<script setup lang="ts">
import { IElFormRule } from '@/types/element-plus'
import { PropType, ref, watch } from 'vue'
const props = defineProps({
  modelValue: {
    type: Object as PropType<{
      accessTokenLifeTime: number
      accessTokenType: number
      consentLifetime: number
      pairWiseSubjectSalt: string
      includeJwtId: boolean
      userSsoLifetime: number
      userCodeType: string
      deviceCodeLifetime :number
      requirePkce: boolean
      requireClientSecret: boolean
      allowAccessTokensViaBrowser: boolean
    }>,
    required: true
  }
})
interface EmitsType {
  (e: 'update:modelValue', form: {
      accessTokenLifeTime: number
      accessTokenType: number
      consentLifetime: number
      pairWiseSubjectSalt: string
      includeJwtId: boolean
      userSsoLifetime: number
      userCodeType: string
      deviceCodeLifetime :number
      requirePkce: boolean
      requireClientSecret: boolean
      allowAccessTokensViaBrowser: boolean
    }): void
}
const emit = defineEmits<EmitsType>()

const form = ref(props.modelValue)
const rules = ref<IElFormRule>({
})
watch(() => props.modelValue, () => {
  form.value = props.modelValue
}, {
  deep: true
})

watch(form.value, () => {
  emit('update:modelValue', form.value)
})
</script>

<style scoped lang="scss">

</style>
